package com.czy.fx.day1.pane.AnchorPane;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class demo3 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("标题");
        primaryStage.setWidth(800);
        primaryStage.setHeight(800);
        AnchorPane anchorPane1 = new AnchorPane();
        AnchorPane anchorPane2 = new AnchorPane();
        anchorPane1.getChildren().add(anchorPane2);

        primaryStage.setScene(new Scene(anchorPane1));

        anchorPane1.setStyle("-fx-background-color: #EE1169");
        anchorPane2.setStyle("-fx-background-color: #27DA40FF");

        primaryStage.show();

        //响应式布局 管理子组件的位置，设置上边界距离
        AnchorPane.setTopAnchor(anchorPane2,0.0);
        AnchorPane.setLeftAnchor(anchorPane2,0.0);
        AnchorPane.setRightAnchor(anchorPane2,anchorPane1.getWidth()/2);
        AnchorPane.setBottomAnchor(anchorPane2,anchorPane1.getHeight()/2);

        anchorPane1.heightProperty().addListener((observable, oldValue, newValue) -> {
            AnchorPane.setBottomAnchor(anchorPane2,newValue.doubleValue()/2);
        });

        anchorPane1.widthProperty().addListener((observable, oldValue, newValue) -> {
            AnchorPane.setRightAnchor(anchorPane2,newValue.doubleValue()/2);
        });

        Button b1 = new Button("b1");
        anchorPane2.getChildren().add(b1);
        AnchorPane.setRightAnchor(b1, 0.0);
        AnchorPane.setBottomAnchor(b1, 0.0);

        /*b1设置 不受父组件管理了，单飞了*/
        b1.setManaged(false);
    }
}
